/*

    This file is part of Hometree.

    Hometree is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Hometree is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Hometree.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2011,2012 Roman Held

*/
#ifndef _HTRS_RESOURCE_HEADER_
#define _HTRS_RESOURCE_HEADER_

/********************************************************************\
                            Includes
\********************************************************************/
#include <QObject>
#include <QString>
#include "htr/htrglobal.h"
#include "htr/mansock.h"

/********************************************************************\
                          Declaration
\********************************************************************/
class HtrsResource : public QObject
{
  Q_OBJECT
  Q_PROPERTY(QString url READ url WRITE setUrl STORED true)
 
  public:
    HtrsResource(const QString &url, Htr::ResourceType type);
    virtual ~HtrsResource();

    void              setUrl(const QString &url);
    QString           url() const;
    Htr::ResourceType type() const;
    qint32            id() const; 

  signals:
    void sendBroadCast(const QByteArray &msg);
    void changed();       // common "Content-Changed"-Event
    void aboutToDelete(); // common "Close"-Event

  public slots:
    // Direktmeldung eines Clients an die Ressource:
    virtual void  cbMsg(qint32 id, HtrManagedSocket *sock);

  protected:
    virtual void  handleMsg(HtrManagedSocket *sock) = 0;
    virtual void  sendError(Htr::Res::Error errCode, HtrManagedSocket *sock);

  private:
    Htr::ResourceType mType;
    QString           mUrl;
    qint32            mId;
  
    static qint32     sNextId;
};

#endif 
